﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Data;
using System.Data.Common;

namespace QLHPHP
{
    /// <summary>
    /// Class ve hoc phi
    /// </summary>
    public static class HocPhi
    {
        /// <summary>
        /// Lay thong tin hoc phi theo MaMonHoc
        /// </summary>
        /// <param name="MaKhoa"></param>
        /// <returns></returns>
        public static DataTable LayThongTinHPTheoMaSV(int MSSV)
        {
            DbCommand comm = DataAccess.CreateCommand();
            comm.CommandText = "GetInfoHPByMSSV";

            DbParameter param = comm.CreateParameter();
            param.ParameterName = "@MSSV";
            param.DbType = DbType.Int32;
            param.Value = MSSV;
            comm.Parameters.Add(param);

            return DataAccess.ExecuteSelectCommand(comm);
        }

        /// <summary>
        /// Lay thong tin hoc phi theo SoPhieuDK
        /// </summary>
        /// <param name="MaKhoa"></param>
        /// <returns></returns>
        public static DataTable LayThongHPTheoSPDK(int SoPhieuDK)
        {
            DbCommand comm = DataAccess.CreateCommand();
            comm.CommandText = "GetInfoHPBySoPhieuDK";

            DbParameter param = comm.CreateParameter();
            param.ParameterName = "@SoPhieuDK";
            param.DbType = DbType.Int32;
            param.Value = SoPhieuDK;
            comm.Parameters.Add(param);

            return DataAccess.ExecuteSelectCommand(comm);
        }

        /// <summary>
        /// Lay so phieu moi nhat tu mssv
        /// </summary>
        /// <param name="MaKhoa"></param>
        /// <returns></returns>
        public static DataTable LaySoPhieuDKMoiNhatTuMSSV(int MSSV)
        {
            DbCommand comm = DataAccess.CreateCommand();
            comm.CommandText = "GetSoPhieuDKMoiNhatByMSSV";

            DbParameter param = comm.CreateParameter();
            param.ParameterName = "@MSSV";
            param.DbType = DbType.Int32;
            param.Value = MSSV;
            comm.Parameters.Add(param);

            return DataAccess.ExecuteSelectCommand(comm);
        }

        /// <summary>
        /// Lay danh sach sinh vien chua dong hoc phi
        /// </summary>
        public static DataTable LayDSChuaDongHP()
        {
            DbCommand comm = DataAccess.CreateCommand();
            comm.CommandText = "GetListChuaDongHocPhi";

            return DataAccess.ExecuteSelectCommand(comm);
        }

        /// <summary>
        /// Lay danh sach sinh vien da dong hoc phi
        /// </summary>
        public static DataTable LayDSDongHocPhi()
        {
            DbCommand comm = DataAccess.CreateCommand();
            comm.CommandText = "GetListDongHocPhi";

            return DataAccess.ExecuteSelectCommand(comm);
        }

        /// <summary>
        /// cap nhap thong tin hoc phi
        /// </summary>
        public static DataTable CapNhapThongTinHocPhi()
        {
            DbCommand comm = DataAccess.CreateCommand();
            comm.CommandText = "UpdateThongTinHocPhi";

            return DataAccess.ExecuteSelectCommand(comm);
        }

        /// <summary>
        /// Tao phieu thu
        /// </summary>
        /// <returns></returns>
        public static bool TaoPhieuThu(int SoPhieuDK, int SoTienThu, DateTime NgayLap)
        {
            DbCommand comm = DataAccess.CreateCommand();
            comm.CommandText = "CreatePhieuThu";

            DbParameter param = comm.CreateParameter();
            param = comm.CreateParameter();
            param.DbType = DbType.Int32;
            param.ParameterName = "@SoPhieuDK";
            param.Value = SoPhieuDK;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.DbType = DbType.Int32;
            param.ParameterName = "@SoTienThu";
            param.Value = SoTienThu;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.DbType = DbType.DateTime;
            param.ParameterName = "@NgayLap";
            param.Value = NgayLap;
            comm.Parameters.Add(param);

            int result = DataAccess.ExecuteNonQuery(comm);
            return (result != -1);
        }
    }
}
